const path = require('path');
const webpackMerge = require('webpack-merge');
const baseConfig = require('./webpack.base.config');
const fs = require('fs')

const HtmlWebPackPlugin = require('html-webpack-plugin');
//用于在构建前清除dist目录中的内容
const { CleanWebpackPlugin } = require('clean-webpack-plugin');


let config = webpackMerge(baseConfig, {
    entry: './docs/index.js', // 入口文件
    output: {
        path: path.resolve(__dirname, '../docs/dist'), // 定义输出目录
        filename: 'index.js'  // 定义输出文件名称
    },
    mode: "development",
    devtool: "source-map",
    resolve: {
        alias: {
            '@doc2com': path.join(__dirname, '../src/')
        }
    },
    module: {
        rules: [{
            test: /\.mdx?$/,
            use: ['babel-loader', '@mdx-js/loader']
        }]
    },
    devServer: {
        hot: true, // 热替换
        contentBase: path.join(__dirname, '../docs/dist'), // server文件的根目录
        compress: true, // 开启gzip
        port: 8082, // 端口
    },
    plugins: [
        // new webpack.HotModuleReplacementPlugin(), // HMR允许在运行时更新各种模块，而无需进行完全刷新
        new CleanWebpackPlugin(),
        new HtmlWebPackPlugin({
            template: './docs/index.html',
            filename: path.resolve(__dirname, '../docs/dist/index.html')
        })
    ],
});


fs.writeFile(path.join(__dirname, '../log/stdout.json'), JSON.stringify(config, null, '\t'), function () { });

module.exports = config;